#pragma once
#include "cpputil.h"
#include "guid.h"
#include <vector>


class GtdDOMData;


class GtdProject;
class GtdContext;
class GtdTaskEntry;
class GtdTaskItem;
class GtdDOMItem;
class TaskEntryCheckItem;

class GtdDOM : public cpputil::noncopyable
{
public:
	GtdDOM(void);
	~GtdDOM(void);

	void Clear();

	//update task entry
	void Update();

	void AddTaskEntry(GtdTaskEntry* pEntry); 
	GuidList GetTaskEntryList()const;
	GuidList GetContextList()const;

	GuidList GetContextTaskItemList(const CGuid& context)const;
	GuidList GetUnContextTaskItemList()const;

	void SetContextList(const GuidList& newlist);

	GtdTaskEntry* GetTaskEntry(const CGuid& id)const;

	GtdDOMItem* getItem(const CGuid& gid)const;
	

	template<class T>
	T* allocateDOMItem()
	{
		T* t = new T(this);
		vAllocateItems.push_back(t);
		return t;
	}
	

	void load(const CString& sfile); //read from file
	void save(const CString& sfile); //save to file
	void update(); //update item state	
protected:
	GtdDOMData* m_pData;
	GtdDOMData* getData()const{ return m_pData; }
	std::vector<GtdDOMItem*> vAllocateItems;
};

